import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'highlight'
})
export class HighlightPipe implements PipeTransform {
    transform(value: string, args: string): any {
        var re = new RegExp(args.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi'); //escape special characters and search is multiple case insensitive
        return value.replace(re, "<mark>$&</mark>"); //adds tags betwen the substring found to match the args
    }
}